home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995 February: Tool Chest / Dev.CD Feb 95 / Dev.CD Feb 95.toast / Tool Chest / QuickDraw GX / QuickDraw GX Info / QuickDraw GX Interfaces / Interfaces & Libraries / graphics libraries / graphics state library.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-30  |  2.4 KB  |  96 lines  |  [TEXT/MPS ]

  1. /* graphics libraries:
  2.    graphics state routines 
  3.    by Cary Clark, Georgiann Delaney, Michael Fairman, Dave Good, Robert Johnson, Keith McGreggor, Oliver Steele, David Van Brink, Chris Yerga
  4.    Copyright 1987 - 1991 Apple Computer, Inc.  All rights reserved.  */
  5.  
  6.    #include <Memory.h>
  7. #include "graphics libraries.h"
  8. #include "graphics state library.h"
  9.  
  10. graphicsState lastGraphicsState = nil;
  11.  
  12. graphicsState NewGraphicsState(void)
  13. {
  14.    graphicsState state = (graphicsState) NewPtr(sizeof(graphicsStateRecord));
  15.    short i;
  16.    
  17.    IfErrorReturnNil(state == nil, out_of_memory);
  18.    for (i = gxEmptyType; i <= gxPictureType; i++)
  19.       state->defaultShapes[i - 1] = GXGetDefaultShape(i);
  20.    return lastGraphicsState = state;
  21. }
  22.  
  23. void DisposeGraphicsState(graphicsState state)
  24. {
  25.    NilParamReturn(state);
  26.    if (lastGraphicsState == state)
  27.       lastGraphicsState = nil;
  28.    DisposePtr((Ptr) state);
  29. }
  30.  
  31. void GetGraphicsState(graphicsState state)
  32. {
  33.    short i;
  34.    
  35.    NilParamReturn(state);
  36.    for (i = gxEmptyType; i <= gxPictureType; i++) {
  37.       gxShape def = GXGetDefaultShape(i);
  38.       if (state->defaultShapes[i - 1] != def) {
  39.          GXDisposeShape(state->defaultShapes[i - 1]);
  40.          state->defaultShapes[i - 1] = def;
  41.       }
  42.    }
  43. }
  44.  
  45. void SetGraphicsState(graphicsState state)
  46. {
  47.    short i;
  48.    
  49.    NilParamReturn(state);
  50.    for (i = gxEmptyType; i <= gxPictureType; i++)
  51.       GXSetDefaultShape(state->defaultShapes[i - 1]);
  52.    lastGraphicsState = state;
  53. }
  54.  
  55. graphicsState SwapGraphicsState(graphicsState state)
  56. {
  57.    graphicsState lastState = lastGraphicsState;
  58.    
  59.    if (lastGraphicsState)
  60.       SetGraphicsState(lastGraphicsState);
  61.    if (state)
  62.       SetGraphicsState(state);
  63.    lastGraphicsState = state;
  64.    return lastState;
  65. }
  66.  
  67. gxStyle SeparateShapeStyle(gxShape source)
  68. {
  69.    gxStyle old = GXCloneStyle(GXGetShapeStyle(source)), xnew = GXCopyToStyle(nil, old);
  70.    GXSetShapeStyle(source, xnew);
  71.    GXDisposeStyle(xnew);
  72.    return old;
  73. }
  74.  
  75. void ReuniteShapeStyle(gxShape target, gxStyle separate)
  76. {
  77.    GXSetShapeStyle(target, separate);
  78.    GXDisposeStyle(separate);
  79.    return;
  80. }
  81.  
  82. gxInk SeparateShapeInk(gxShape source)
  83. {
  84.    gxInk old = GXCloneInk(GXGetShapeInk(source)), xnew = GXCopyToInk(nil, old);
  85.    GXSetShapeInk(source, xnew);
  86.    GXDisposeInk(xnew);
  87.    return old;
  88. }
  89.  
  90. void ReuniteShapeInk(gxShape target, gxInk separate)
  91. {
  92.    GXSetShapeInk(target, separate);
  93.    GXDisposeInk(separate);
  94.    return;
  95. }
  96.